<?php


namespace app\admin\controller;


use easyadmin\app\columns\form\FormHidden;
use easyadmin\app\columns\form\FormText;
use easyadmin\app\columns\lists\ListDateTime;
use easyadmin\app\columns\lists\ListText;
use easyadmin\app\libs\ListField;
use easyadmin\app\libs\PageForm;
use easyadmin\app\libs\PageList;
use easyadmin\app\libs\Pagination;
use easyadmin\app\libs\Verify;

class Task extends Admin
{

    protected $softDeleteField = 'is_delete';
    protected $tableName = "task";
    protected $pageName = '任务管理';
    protected function configListField(ListField $list)
    {
        $list
            ->addField('id', 'ID', ListText::class)
            ->addField('task_name', '任务名', ListText::class)
            ->addField('task_lv', '任务等级', ListText::class)
            ->addField('task_profit', '任务收益', ListText::class)
            ->addField('task_type', '任务类型', ListText::class, [
                'class' => 'task-type',
                'jsFiles' => ['/lib/index.js']
            ])
            ->addField('task_description', '任务描述', ListText::class)
            ->addField('task_total', '任务可领取总次数', ListText::class)
            ->addField('task_complete', '任务已领取总次数', ListText::class)
            ;
    }

    protected function configShowField(ListField $field)
    {
        $field
            ->addField('task_name', '任务名', ListText::class)
            ->addField('task_no', '任务编号', ListText::class)
            ->addField('task_lv', '任务等级', ListText::class)
            ->addField('task_profit', '任务收益', ListText::class)
            ->addField('task_type', '任务类型', ListText::class)
            ->addField('task_description', '任务描述', ListText::class)
            ->addField('task_total', '任务可领取总次数', ListText::class)
            ->addField('task_complete', '任务已领取总次数', ListText::class)
            ->addField('task_create_time', '任务创建时间', ListDateTime::class)
            ->addField('task_status', '任务状态 0:可用 1:任务次数已用完', ListText::class)
            ;
    }

    protected function configFormField(PageForm $page)
    {
        $page
            ->addField('task_name', '任务名', FormText::class, [
                'required' => true
            ])
            ->addField('task_lv', '任务等级', FormText::class, [
                'required' => true
            ])
            ->addField('task_profit', '任务收益', FormText::class, [
                'required' =>true,
            ])
            ->addField('task_type', '任务类型:101 微视; 201 小红书; 301 快手; 401 抖音;', FormText::class, [
                'required'  => true
            ])
            ->addField('task_description', '任务描述', FormText::class, [
                'required' => true
            ])
            ->addField('task_total', '任务可领取总次数', FormText::class, [
                'required' => true,
                'verify' => (new Verify())
                            ->addRule('number', '请输入数字')
            ])
            ;
    }
    protected function configListPagination(Pagination $pagination)
    {
        $pagination->setPageSize(20);
    }

    protected function insertBefore($data): array
    {
        $data['task_no'] = date('Ymd',time()) . time();
        $data['task_create_time'] = time();
        $data['is_delete'] = 0;
        $data['task_complete'] = 0;
        $data['task_status'] = 0;
        $data['task_remainder'] = $data['task_total'];
        return $data;
    }
    protected function configList(PageList $page)
    {
        parent::configList($page);
        $page
            ->setTemplate("list:list")
            ->setOrderBy(['id'=>"desc"])
            ;
    }

}